package com.atguigu.gulimall.order.service.impl;

import com.atguigu.gulimall.order.entity.OrderEntity;
import com.atguigu.gulimall.order.entity.OrderReturnApplyEntity;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.TimeoutException;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;

import com.atguigu.gulimall.order.dao.OrderItemDao;
import com.atguigu.gulimall.order.entity.OrderItemEntity;
import com.atguigu.gulimall.order.service.OrderItemService;
/**
 * 订单项信息
 */
@Service("orderItemService")
//@RabbitListener(queues = {"hello-java-queue"})    //可以放在类上
public class OrderItemServiceImpl extends ServiceImpl<OrderItemDao, OrderItemEntity> implements OrderItemService {

//    @RabbitHandler
//    public void receiverMessage(Message message, OrderReturnApplyEntity content, Channel channel) throws InterruptedException, IOException, TimeoutException {
//        System.out.println("接收到消息...内容: " + content);
//        System.out.println("消息处理完成=> " + content.getReturnName());
//
//        //channel 内按顺序自增的
//        long deliveryTag = message.getMessageProperties().getDeliveryTag();    //获取交货标签
//        System.out.println("deliveryTag:" + deliveryTag);
//
//        try{
//            if (deliveryTag % 2 == 0){
//                //处理消息 (收货)
//                channel.basicAck(deliveryTag, false);    //关闭批量签收
//                System.out.println("签收了货物。。。" + deliveryTag);
//            }else {
//                //退货                         关闭批量签收  是否重新入队
//                channel.basicNack(deliveryTag, false, true);
//                System.out.println("没有签收货物..." + deliveryTag);
//            }
//        }catch (Exception e){
//            //网络中断
//        }
//        channel.close();
//    }
//
//    @RabbitHandler
//    public void receiverMessage(OrderEntity orderEntity){
//        System.out.println("接收到消息...内容:" + orderEntity);
//    }
//
//    //@RabbitListener(queues = {"hello-java-queue"})    //也可以放在方法上
////    @RabbitHandler
//
//    public void receiverMessage1(Message message, OrderReturnApplyEntity content, Channel channel) throws Exception {
//        //消息体
//        byte[] body = message.getBody();
//        //消息头属性信息
//        MessageProperties properties = message.getMessageProperties();
//        System.out.println("接收到消息...内容: " + content);
//        //Thread.sleep(3000);
//        System.out.println("消息处理完成 => " + content.getReturnName());
//    }


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<OrderItemEntity> page = this.page(
                new Query<OrderItemEntity>().getPage(params),
                new QueryWrapper<OrderItemEntity>()
        );
        return new PageUtils(page);
    }
}